From 340643863ba2e9d1d93f17880f5f16317974c5e6 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Wed, 20 Jun 2007 15:33:14 +0100 Subject: [PATCH] Use clear_page() wherever possible/reasonable instead of open coded memset() calls (likewise a few replacements memcpy -> copy_page). Signed-off-by: Jan Beulich --- xen/arch/ia64/xen/domain.c | 9 ++++----- xen/arch/ia64/xen/xenmem.c | 2 +- xen/arch/x86/apic.c | 4 ++-- xen/arch/x86/domain.c | 2 +- xen/arch/x86/domain_build.c | 6 +++--- xen/arch/x86/hvm/svm/svm.c | 2 -- xen/arch/x86/hvm/svm/vmcb.c | 6 +++--- xen/arch/x86/hvm/vlapic.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 -- xen/arch/x86/x86_32/traps.c | 1 + xen/arch/x86/x86_64/traps.c | 1 + xen/common/grant_table.c | 12 ++++++------ 13 files changed, 24 insertions(+), 27 deletions(-) diff --git a/xen/arch/ia64/xen/domain.c b/xen/arch/ia64/xen/domain.c index f85214e4b6..c9bd12d432 100644 --- a/xen/arch/ia64/xen/domain.c +++ b/xen/arch/ia64/xen/domain.c @@ -1146,9 +1146,8 @@ static void __init loaddomainelfimage(struct domain *d, struct elf_binary *elf, dom_imva = __va_ul(page_to_maddr(p)); if (filesz > 0) { if (filesz >= PAGE_SIZE) - memcpy((void *) dom_imva, - (void *) elfaddr, - PAGE_SIZE); + copy_page((void *) dom_imva, + (void *) elfaddr); else { // copy partial page memcpy((void *) dom_imva, @@ -1166,7 +1165,7 @@ static void __init loaddomainelfimage(struct domain *d, struct elf_binary *elf, } else if (memsz > 0) { /* always zero out entire page */ - memset((void *) dom_imva, 0, PAGE_SIZE); + clear_page((void *) dom_imva); } memsz -= PAGE_SIZE; filesz -= PAGE_SIZE; @@ -1367,7 +1366,7 @@ int __init construct_dom0(struct domain *d, if (start_info_page == NULL) panic("can't allocate start info page"); si = page_to_virt(start_info_page); - memset(si, 0, PAGE_SIZE); + clear_page(si); snprintf(si->magic, sizeof(si->magic), "xen-%i.%i-ia64", xen_major_version(), xen_minor_version()); si->nr_pages = max_pages; diff --git a/xen/arch/ia64/xen/xenmem.c b/xen/arch/ia64/xen/xenmem.c index 54cc21be7b..47c3742eee 100644 --- a/xen/arch/ia64/xen/xenmem.c +++ b/xen/arch/ia64/xen/xenmem.c @@ -90,7 +90,7 @@ alloc_dir_page(void) panic("Not enough memory for virtual frame table!\n"); ++table_size; dir = mfn << PAGE_SHIFT; - memset(__va(dir), 0, PAGE_SIZE); + clear_page(__va(dir)); return dir; } diff --git a/xen/arch/x86/apic.c b/xen/arch/x86/apic.c index f934a30506..3c6a14d43c 100644 --- a/xen/arch/x86/apic.c +++ b/xen/arch/x86/apic.c @@ -817,7 +817,7 @@ void __init init_apic_mappings(void) */ if (!smp_found_config && detect_init_APIC()) { apic_phys = __pa(alloc_xenheap_page()); - memset(__va(apic_phys), 0, PAGE_SIZE); + clear_page(__va(apic_phys)); } else apic_phys = mp_lapic_addr; @@ -852,7 +852,7 @@ void __init init_apic_mappings(void) } else { fake_ioapic_page: ioapic_phys = __pa(alloc_xenheap_page()); - memset(__va(ioapic_phys), 0, PAGE_SIZE); + clear_page(__va(ioapic_phys)); } set_fixmap_nocache(idx, ioapic_phys); apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n", diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 63364b0e8e..79dc4baa37 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -476,7 +476,7 @@ int arch_domain_create(struct domain *d) if ( (d->shared_info = alloc_xenheap_page()) == NULL ) goto fail; - memset(d->shared_info, 0, PAGE_SIZE); + clear_page(d->shared_info); share_xen_page_with_guest( virt_to_page(d->shared_info), d, XENSHARE_writable); } diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c index dffa7ce345..e57e33e617 100644 --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -505,7 +505,7 @@ int __init construct_dom0( v->arch.guest_table = pagetable_from_paddr((unsigned long)l3start); #else l2start = l2tab = (l2_pgentry_t *)mpt_alloc; mpt_alloc += PAGE_SIZE; - memcpy(l2tab, idle_pg_table, PAGE_SIZE); + copy_page(l2tab, idle_pg_table); l2tab[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] = l2e_from_paddr((unsigned long)l2start, __PAGE_HYPERVISOR); v->arch.guest_table = pagetable_from_paddr((unsigned long)l2start); @@ -645,7 +645,7 @@ int __init construct_dom0( panic("Not enough RAM for domain 0 PML4.\n"); l4start = l4tab = page_to_virt(page); } - memcpy(l4tab, idle_pg_table, PAGE_SIZE); + copy_page(l4tab, idle_pg_table); l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] = l4e_from_paddr(__pa(l4start), __PAGE_HYPERVISOR); l4tab[l4_table_offset(PERDOMAIN_VIRT_START)] = @@ -823,7 +823,7 @@ int __init construct_dom0( /* Set up start info area. */ si = (start_info_t *)vstartinfo_start; - memset(si, 0, PAGE_SIZE); + clear_page(si); si->nr_pages = nr_pages; si->shared_info = virt_to_maddr(d->shared_info); diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 1dfbfd763f..9275a01052 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -766,8 +766,6 @@ static void svm_init_hypercall_page(struct domain *d, void *hypercall_page) char *p; int i; - memset(hypercall_page, 0, PAGE_SIZE); - for ( i = 0; i < (PAGE_SIZE / 32); i++ ) { p = (char *)(hypercall_page + (i * 32)); diff --git a/xen/arch/x86/hvm/svm/vmcb.c b/xen/arch/x86/hvm/svm/vmcb.c index a459f2ca09..c6b1ccddea 100644 --- a/xen/arch/x86/hvm/svm/vmcb.c +++ b/xen/arch/x86/hvm/svm/vmcb.c @@ -56,7 +56,7 @@ struct vmcb_struct *alloc_vmcb(void) return NULL; } - memset(vmcb, 0, PAGE_SIZE); + clear_page(vmcb); return vmcb; } @@ -72,11 +72,11 @@ struct host_save_area *alloc_host_save_area(void) hsa = alloc_xenheap_page(); if ( hsa == NULL ) { - printk(XENLOG_WARNING "Warning: failed to allocate vmcb.\n"); + printk(XENLOG_WARNING "Warning: failed to allocate hsa.\n"); return NULL; } - memset(hsa, 0, PAGE_SIZE); + clear_page(hsa); return hsa; } diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 99ca287400..98d346f85a 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -934,7 +934,7 @@ int vlapic_init(struct vcpu *v) return -ENOMEM; } - memset(vlapic->regs, 0, PAGE_SIZE); + clear_page(vlapic->regs); vlapic_reset(vlapic); diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 6ca6a4e9b8..1740277c8e 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -158,7 +158,7 @@ static struct vmcs_struct *vmx_alloc_vmcs(void) return NULL; } - memset(vmcs, 0, PAGE_SIZE); + clear_page(vmcs); vmcs->vmcs_revision_id = vmcs_revision_id; return vmcs; diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 74d793c445..f36b58f261 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1070,8 +1070,6 @@ static void vmx_init_hypercall_page(struct domain *d, void *hypercall_page) char *p; int i; - memset(hypercall_page, 0, PAGE_SIZE); - for ( i = 0; i < (PAGE_SIZE / 32); i++ ) { p = (char *)(hypercall_page + (i * 32)); diff --git a/xen/arch/x86/x86_32/traps.c b/xen/arch/x86/x86_32/traps.c index a837d7e42d..c3fc0fdd2a 100644 --- a/xen/arch/x86/x86_32/traps.c +++ b/xen/arch/x86/x86_32/traps.c @@ -513,6 +513,7 @@ static void hypercall_page_initialise_ring1_kernel(void *hypercall_page) void hypercall_page_initialise(struct domain *d, void *hypercall_page) { + memset(hypercall_page, 0xCC, PAGE_SIZE); if ( is_hvm_domain(d) ) hvm_hypercall_page_initialise(d, hypercall_page); else if ( supervisor_mode_kernel ) diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c index e23ed82c75..6b14040a14 100644 --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -510,6 +510,7 @@ static void hypercall_page_initialise_ring3_kernel(void *hypercall_page) void hypercall_page_initialise(struct domain *d, void *hypercall_page) { + memset(hypercall_page, 0xCC, PAGE_SIZE); if ( is_hvm_domain(d) ) hvm_hypercall_page_initialise(d, hypercall_page); else if ( !is_pv_32bit_domain(d) ) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index d6581f66cf..15e72aea7c 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -148,7 +148,7 @@ get_maptrack_handle( return -1; } - memset(new_mt, 0, PAGE_SIZE); + clear_page(new_mt); new_mt_limit = lgt->maptrack_limit + MAPTRACK_PER_PAGE; @@ -624,7 +624,7 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) { if ( (gt->active[i] = alloc_xenheap_page()) == NULL ) goto active_alloc_failed; - memset(gt->active[i], 0, PAGE_SIZE); + clear_page(gt->active[i]); } /* Shared */ @@ -632,7 +632,7 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) { if ( (gt->shared[i] = alloc_xenheap_page()) == NULL ) goto shared_alloc_failed; - memset(gt->shared[i], 0, PAGE_SIZE); + clear_page(gt->shared[i]); } /* Share the new shared frames with the recipient domain */ @@ -1365,7 +1365,7 @@ grant_table_create( { if ( (t->active[i] = alloc_xenheap_page()) == NULL ) goto no_mem_2; - memset(t->active[i], 0, PAGE_SIZE); + clear_page(t->active[i]); } /* Tracking of mapped foreign frames table */ @@ -1375,7 +1375,7 @@ grant_table_create( memset(t->maptrack, 0, max_nr_maptrack_frames() * sizeof(t->maptrack[0])); if ( (t->maptrack[0] = alloc_xenheap_page()) == NULL ) goto no_mem_3; - memset(t->maptrack[0], 0, PAGE_SIZE); + clear_page(t->maptrack[0]); t->maptrack_limit = PAGE_SIZE / sizeof(struct grant_mapping); for ( i = 0; i < t->maptrack_limit; i++ ) t->maptrack[0][i].ref = i+1; @@ -1389,7 +1389,7 @@ grant_table_create( { if ( (t->shared[i] = alloc_xenheap_page()) == NULL ) goto no_mem_4; - memset(t->shared[i], 0, PAGE_SIZE); + clear_page(t->shared[i]); } for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ ) -- 2.30.2